﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<WebSite.Models.NormalBudgetUploadModel>" %>
<%@ Import Namespace="WebSite.Models" %>
<%@ Import Namespace="WebSite.App_Code" %>
<%@ Import Namespace="WebSite.App_Data" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
	NormalBudgetUpload
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    
    <link href="../../Scripts/jquery-ui/css/redmond/jquery-ui-1.9.2.custom.min.css" rel="stylesheet" />
    <script type="text/javascript" src="../../Scripts/jquery-ui/js/jquery-ui-1.9.2.custom.min.js"></script>
    
    <script type="text/javascript" src="../../Scripts/jquery-pending/jquery-pending.js"></script>

    <script type="text/javascript">

        $(document).ready(function () {

            //$("#progressbar").progressbar({ value: false });

            if ('<%=ViewData.ContainsKey("DB.Operation.Result") %>' == "True")
                alert('<%=ViewData["DB.Operation.Result"] %>');
            
            <% if (Session["Budget.Data.Review"] != null || ViewData["Budget.Data.Review"] != null) { %>
                $(function () {
                    $("#dialog-UploadReview").dialog({
                        height: 500,
                        width: 800,
                        modal: true
                    });
                });
            <% } %>

        });

        function Pending(on_off) {

            if (on_off) {

                $("#dialog-Wait").pending({
                    height: 30,
                    width: 24,
                    modal: true
                });
            }
            else {

                $("#dialog-Wait").pending(false);
            }
        }

        function openUploadWin() {

            $(function () {
                $("#dialog-UploadTemplate").dialog({
                    height: 240,
                    width: 500,
                    modal: true
                });
            });
        }

        function SelectOneBudget(sender, pc) {

            var tb = $(sender).parents("table:eq(0)");
            var checkbox = $("input[type=checkbox][IsAll=0]:checked", tb);

            var ids = "";

            for (var i = 0; i < checkbox.length; i++) {
                ids = ids + checkbox.eq(i).attr("BudgetId") + ",";
            }

            $("#Budget_ProCategory_" + pc +  "_ID_List").val(ids);
            $("#Budget_ProCategory_" + pc +  "_ID_List_").val(ids);
            $("#Budget_ProCategory_" + pc +  "_ID_List__").val(ids);
        }

        function SelectAllBudget(sender, pc) {

            var tb = $(sender).parents("table:eq(0)");
            var checkbox = $("input[type=checkbox][IsAll=0]", tb);

            for (var i = 0; i < checkbox.length; i++) {
                checkbox[i].checked = sender.checked;
            }

            SelectOneBudget(sender, pc);
        }

    </script>

    <% 
        List<BudgetItem> lsBudgetItem = new List<BudgetItem>(); 
       
        if (ViewData["Budget.NormalBudgetUpload.BudgetList"] != null)
            lsBudgetItem = (List<BudgetItem>)ViewData["Budget.NormalBudgetUpload.BudgetList"];
            
    %>

    <table>
        <tr>
            <td><b>年度：<%=Model.CurrentYear %></b></td>
            <td><input type="button" value="提交" <%=(lsBudgetItem.Any() ? "" : "disabled") %>  onclick="openUploadWin()" class="budget-button-no-01"/></td>
        </tr>
    </table>

    <%  //预算科研
        if (lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "1").Any())
        {
            List<BudgetItem> lsBudgetItem_1 = lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "1").ToList();
            %>
            <br />
            <table>
                <tr>
                    <td><b>预算科研</b></td>
                    <td>
                        <% using (Html.BeginForm("NormalBudgetUpload_DownloadTemplate", "Budget", new { id = 1 })) { %>
                            <input type="submit" value="下载预算模板" class="budget-button-no-01"/>
                            <input type="hidden" name="BudgetList" id="Budget_ProCategory_1_ID_List" />
                        <% } %>
                    </td>
                </tr>
            </table>

            <table border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
                <thead>
                    <tr>
                        <td><input type="checkbox" IsAll="1" onclick="SelectAllBudget(this, 1)"/></td>
                        <td>编制单位</td>
                        <td>项目名称</td>
                        <td>项目代号</td>
                        <td>项目周期-起</td>
                        <td>项目周期-止</td>
                        <td>年度进度</td>
                        <td>项目负责人</td>
                        <td>状态</td>
                        <td class="last"></td>
                    </tr>
                </thead>
                <tbody>
                <% foreach (BudgetItem One in lsBudgetItem_1)
                   { %>
                <tr>
                    <td>
                        <input type="checkbox" onclick="SelectOneBudget(this, 1)" IsAll="0" BudgetId="<%=One.Budget.Guid %>" />
                    </td>
                    <td><%=One.Project.Department.DepartmentName %></td>
                    <td><a style="color:Blue; text-decoration:underline; cursor:pointer" onclick="OpenBudegt('<%=One.Budget.Guid %>', 'false', '')" ><%=One.Project.Project.ProjectName %></a></td>              
                    <td><%=One.Project.Project.ProjectCode %></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectBeginTime)%></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectEndTime) %></td>
                    <td><%=One.Budget.AnnualProgress %></td>
                    <td><%=One.Project.ProjcetPIC.UserName %></td>
                    <td><%=One.BS.Name %></td>
                    <td>
                        <% if (Model.U.AppCan(L_ActionType.Delete
                               , new list_ProjectCategory() { ID = One.Project.ProjectCategory.ID }
                               , new md_Department() { Guid = One.Project.Department.Guid }
                               , new md_User() { Guid = One.Project.ProjcetPIC.Guid }
                               , new list_BudgetStatus() { Status = One.Budget.BudgetStatus }))
                           { %>
                             <% using (Html.BeginForm("NormalBudgetUpload_Delete", "Budget", new { id = One.Budget.Guid }))
                                { %>
                                <input type="submit" name="DeleteBudget" id="btnDeleteBudget" value="删除" class="budget-button-no-01" onclick="return confirm('确定要删除项目代号“<%=One.Project.Project.ProjectCode %>”的预算吗？')"/>
                            <% } %>                       
                        <% } %>
                    </td>
                </tr>
                <% } %>
                </tbody>
            </table>
               
        <%  
            }

        //预算外科研
        if (lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "2").Any())
        {
            List<BudgetItem> lsBudgetItem_2 = lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "2").ToList();
               
            %>
            <br />
            <table>
                <tr>
                    <td><b>预算外科研</b></td>
                    <td>
                        <% using (Html.BeginForm("NormalBudgetUpload_DownloadTemplate", "Budget", new { id = 2 })) { %>
                            <input type="submit" value="下载预算模板" class="budget-button-no-01"/>
                            <input type="hidden" name="BudgetList" id="Budget_ProCategory_2_ID_List" />
                        <% } %>
                    </td>
                </tr>
            </table>

            <table  border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
                <thead>
                <tr>
                    <td><input type="checkbox" IsAll="1" onclick="SelectAllBudget(this, 2)"/></td>
                    <td>编制单位</td>
                    <td>项目名称</td>
                    <td>项目代号</td>
                    <td>项目周期-起</td>
                    <td>项目周期-止</td>
                    <td>年度进度</td>
                    <td>项目负责人</td>
                        <td>状态</td>
                        <td class="last"></td>
                </tr>
                </thead>
                <tbody>
                <% foreach (BudgetItem One in lsBudgetItem_2) { %>
                <tr>
                    <td>
                        <input type="checkbox" onclick="SelectOneBudget(this, 2)" IsAll="0" BudgetId="<%=One.Budget.Guid %>" />
                    </td>
                    <td><%=One.Project.Department.DepartmentName %></td>
                    <td><a style="color:Blue; text-decoration:underline; cursor:pointer" onclick="OpenBudegt('<%=One.Budget.Guid %>', 'false', '')" ><%=One.Project.Project.ProjectName %></a></td>
                    <td><%=One.Project.Project.ProjectCode %></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectBeginTime) %></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectEndTime) %></td>
                    <td><%=One.Budget.AnnualProgress %></td>
                    <td><%=One.Project.ProjcetPIC.UserName %></td>
                    <td><%=One.BS.Name %></td>
                    <td>
                        <% if (Model.U.AppCan(L_ActionType.Delete
                               , new list_ProjectCategory() { ID = One.Project.ProjectCategory.ID }
                               , new md_Department() { Guid = One.Project.Department.Guid }
                               , new md_User() { Guid = One.Project.ProjcetPIC.Guid }
                               , new list_BudgetStatus() { Status = One.Budget.BudgetStatus }))
                           { %>
                             <% using (Html.BeginForm("NormalBudgetUpload_Delete", "Budget", new { id = One.Budget.Guid })) { %>
                                <input type="submit" name="DeleteBudget" id="Submit1" value="删除" class="budget-button-no-01" onclick="return confirm('确定要删除项目代号“<%=One.Project.Project.ProjectCode %>”的预算吗？')"/>
                            <% } %>                       
                        <% } %>
                    </td>
                </tr>
                <% } %>
                </tbody>
            </table>

            <%
        }

        //有偿服务
        if (lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "3").Any())
        {
            List<BudgetItem> lsBudgetItem_3 = lsBudgetItem.Where(o => o.Project.ProjectCategory.ID == "3").ToList();
               
            %>
            <br />
            <table border="0" cellpadding="0" cellspacing="1" class="List">
                <tr>
                    <td><b>有偿服务</b></td>
                    <td>
                        <% using (Html.BeginForm("NormalBudgetUpload_DownloadTemplate", "Budget", new { id = 3 })) { %>
                            <input type="submit" value="下载预算模板" class="budget-button-no-01"/>
                            <input type="hidden" name="BudgetList" id="Budget_ProCategory_3_ID_List" />
                        <% } %>
                    </td>
                </tr>
            </table>

            <table  border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
                <thead>
                <tr>
                    <td><input type="checkbox" IsAll="1" onclick="SelectAllBudget(this, 3)"/></td>
                    <td>编制单位</td>
                    <td>项目名称</td>
                    <td>项目代号</td>
                    <td>项目周期-起</td>
                    <td>项目周期-止</td>
                    <td>年度进度</td>
                    <td>项目负责人</td>
                        <td>状态</td>
                        <td class="last"></td>
                </tr>
                </thead>
                <tbody>
                <% foreach (BudgetItem One in lsBudgetItem_3) { %>                
                <tr>
                    <td>
                        <input type="checkbox" onclick="SelectOneBudget(this, 3)" IsAll="0" BudgetId="<%=One.Budget.Guid %>" />
                    </td>
                    <td><%=One.Project.Department.DepartmentName %></td>
                    <td><a style="color:Blue; text-decoration:underline; cursor:pointer" onclick="OpenBudegt('<%=One.Budget.Guid %>', 'false', '')" ><%=One.Project.Project.ProjectName %></a></td>
                    <td><%=One.Project.Project.ProjectCode %></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectBeginTime) %></td>
                    <td><%=CommonItem.X_yyyyMMdd(One.Project.Project.ProjectEndTime) %></td>
                    <td><%=One.Budget.AnnualProgress %></td>
                    <td><%=One.Project.ProjcetPIC.UserName %></td>
                    <td><%=One.BS.Name %></td>
                    <td>
                        <% if (Model.U.AppCan(L_ActionType.Delete
                               , new list_ProjectCategory() { ID = One.Project.ProjectCategory.ID }
                               , new md_Department() { Guid = One.Project.Department.Guid }
                               , new md_User() { Guid = One.Project.ProjcetPIC.Guid }
                               , new list_BudgetStatus() { Status = One.Budget.BudgetStatus }))
                           { %>
                             <% using (Html.BeginForm("NormalBudgetUpload_Delete", "Budget", new { id = One.Budget.Guid })) { %>
                                <input type="submit" name="DeleteBudget" id="Submit2" value="删除" class="budget-button-no-01" onclick="return confirm('确定要删除项目代号“<%=One.Project.Project.ProjectCode %>”的预算吗？')"/>
                            <% } %>                       
                        <% } %>
                    </td>
                </tr>
                <% } %>
                </tbody>
            </table>

            <%
        } %>

        <div id="dialog-UploadTemplate" title="模板提交" style=" display:none">
            <table border="0" cellpadding="0" cellspacing="0" style=" width:100%" >
                <tr>
                    <td colspan="4" style=" font-size:large; text-align:center; padding:10px 0px 5px 0px">
                        该页面仅用于提交非机关费预算，<br />
                        机关费预算请使用【机关费提交】页面提交
                    </td>
                </tr>
                <tr>
                    <td style=" width:50px"></td>
                    <td style="color:Red;">
                        注意：
                    </td>
                    <td style="color:Red; ">
                        1. 每次只能上传一个文件                    
                    </td>
                    <td style=" width:50px"></td>
                </tr>
                <tr>
                    <td style=" width:50px"></td>
                    <td></td>
                    <td style="color:Red;">
                        2.每个文件中可以包含多个预算，但必须为同一个预算类别
                    </td>
                    <td style=" width:50px"></td>
                </tr>
                <tr>
                    <td colspan="4" align="center" style=" padding:40px 0px 0px 0px">
                        <% using (Html.BeginForm("NormalBudgetUpload_Upload", "Budget", FormMethod.Post, new { enctype = "multipart/form-data" }))
                           { %>
                        <input type="file" name="uploadBudget" style=" width:300px" class="budget-button-no-01" />
                        <input type="submit" value="提交" class="budget-button-no-01" onclick="Pending(true)" />
                        <%} %>
                    </td>
                </tr>
            </table>
        </div>

        <div id="dialog-UploadReview" title="模板确认" style=" display:none; padding:20px">
            
            <span style=" font-size:large;">
            以下为本次上传的预算信息的检查结果。<br />
            请确认每项预算的处理方案和检查中发现的错误
            </span>
            <br />
            <br />
            <% List<TemplateSheetItem> Table = new List<TemplateSheetItem>();

                if (Session["Budget.Data.Review"] != null)
                    Table = (List<TemplateSheetItem>)Session["Budget.Data.Review"];
                else if (ViewData["Budget.Data.Review"] != null)
                    Table = (List<TemplateSheetItem>)ViewData["Budget.Data.Review"];
            %>

            <%if (Table.Count > 0) { %>
                <% int ErrorCount = 0; %>
                <table border="0" cellpadding="0" cellspacing="0" class="budget-table-no-01">
                    <thead>
                    <tr>
                        <td>编制单位</td>
                        <td>项目名称</td>
                        <td>项目负责人</td>
                        <td>是否垫支</td>
                        <td>垫支金额</td>
                        <td>预算金额</td>
                        <td>检查结果</td>
                        <td class="last">处理方案</td>
                    </tr>
                    </thead>
                    <tbody>
                    <%  foreach (TemplateSheetItem Sheet in Table) 
                        {
                            Dictionary<String, ExcelSheetCellItem> Row = Sheet.BugetInfo;
                            if (!Sheet.IsOK)
                                ErrorCount++;
                    %>
                    <tr>
                        <td><%=Row["编制单位"].Text %></td>
                        <td><%=Row["项目名称"].Text %></td>
                        <td><%=Row["项目负责人"].Text %></td>
                        <td><%=Row["是否垫支"].Text%></td>
                        <td><%=Row["垫支金额"].Text %></td>
                        <td><%=Row["预算金额"].Text %></td>
                        <td><%=Row["检查结果"].Text %></td>
                        <td><%=Row["处理方案"].Text %></td>
                    </tr>
                    <% } %>
                    </tbody>
                </table>

                <% if (ErrorCount == 0 && Session["Budget.Data.Review"] != null)
                   { %>
                    <% using (Html.BeginForm("NormalBudgetUpload_Submit", "Budget", FormMethod.Post))
                   { %>
                        <br />
                        <input type="submit" value="确认提交" class="budget-button-no-01" onclick="Pending(true)" />
                    <% } %>        
                <% }  %>
            <% } %>

        </div>

        <div id="dialog-Wait" style=" text-align:center; padding:0px; display:none; overflow:hidden">
            <img src="../../Style/Img/loading-01.GIF" />
        </div>
</asp:Content>
